package com.wxy.xr.dao.impl;

import com.wxy.xr.bean.Skill;
import com.wxy.xr.dao.SkillDao;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import java.util.ArrayList;
import java.util.List;

public class SkillDaoImpl extends BaseDaoImpl<Skill> implements SkillDao {


    @Override
    public boolean save(Skill bean) {
        Integer id=bean.getId();
        List<Object> args = new ArrayList<>();
        args.add(bean.getName());
        args.add(bean.getLevel());
        String sql;
        if(id==null || id<1){
            sql="INSERT INTO skill(name,level) values(?,?)";
        } else {
            sql="UPDATE skill set name=? ,level =? where id =?";
            args.add(id);
        }
        return tpl.update(sql,args.toArray())>0;
    }

    @Override
    public Skill get(Integer id) {
        String sql="select id, created_time, name,level from skill where id=?";
        return tpl.queryForObject(sql,new BeanPropertyRowMapper<>(Skill.class),id);
    }

    @Override
    public List<Skill> list() {
        String sql="select id, created_time, name,level from skill" ;
        return tpl.query(sql,new BeanPropertyRowMapper<>(Skill.class));
    }
}
